<?php
namespace Admin\Controller;
class TagsController extends CommonController{
    public  $exec_comfunc  = 'index,add,edit,delete';//index,add,edit,delete

    public function _initialize(){
        parent::_initialize();
        $type = $this->_get('type');
        $this->_db_where['module'] = $type;
    }
	// 自动完成标签
	public function autocomplete(){
        $query = htmlspecialchars(trim($this->_get('query')));
        $where['module']  = $this->_get('module');
        $where['content'] = array('like',"%$query%");
        $list = D('Tags')->where($where)->limit("0,10")->select();
        $data  = array();
        if($list){
            foreach($list as $rs){
                $rs['title'] = $rs['content'];
                $rs['value'] = $rs['tags_id'];
                $data[] = $rs;
            }
        }
        $data = json_encode($data);
        exit($data);
    }
    //添加标签
    public function add_content(){
        $content = $this->_post('content', '内容不能为空！');
        $content = str_cut($content, 90, '');
        $field   = $this->_get('field', '字段不能为空！');

		$data['admin_id']    = $this->_user_id;
        $data['content']     = $content;
        $data['module']      = $this->_get('module', '您的操作有误！');
        $data['create_time'] = time();
        D('Tags')->add($data);
        $data['tags_id'] = D('Tags')->getLastInsID();
        $data['field']   = $field;


		$this->success('添加成功！', '', $data);
    }
}


